package hmove;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.Sprite;
import main.*;

public class MoveFly extends Move{
    public MoveFly(Pokemon pokemon) {
        /*String fileName = "/grass.png";
        int w = 24;
        int h = 24;

        try {
            _sprite = new Sprite(Image.createImage(fileName), w, h);
            
            _sprite.defineReferencePixel(w / 2, h / 2);
            _sprite.defineCollisionRectangle(0, 0, w, h);
        } catch (Exception ex) {
        }*/
        throwingObject = new ThrewObject();
        _damage = 100;
        _pokemonOwner = pokemon;
    }
    public void activate(double thrownPower) {
        //_pokemonOwner.
        throwingObject.setThrowParameter(_pokemonOwner.getAngle(), thrownPower);
        throwingObject.activate();
        count = 0;
        //_sprite.setVisible(true);
    }
    public boolean hit(Pokemon pokemon) {

        return false;
    }
    public void deactivate() {
        throwingObject.deactivate();
    }

    public boolean run(Sprite map) {
        
        int x = _pokemonOwner.getSprite().getRefPixelX();
        int y = _pokemonOwner.getSprite().getRefPixelY();
        Point positionPoint = new Point(x, y);
        throwingObject.run(positionPoint);   
        //_sprite.nextFrame();
        boolean checkCollides = count>1;
        Pokemon.moveUpTheGround(_pokemonOwner.getSprite(), map, map.getHeight());
        count ++ ;
        boolean flag = ThrewObject.moveSpriteTo(_pokemonOwner.getSprite(), map, positionPoint.getX(), positionPoint.getY(),checkCollides);
        if(positionPoint.getY()> map.getHeight() )
        {
           _pokemonOwner.incHp(-_pokemonOwner.getHp());
           return flag = true;
        }
        return (flag); 
                //|| positionPoint.getY() > map.getHeight() || positionPoint.getX() < 0 || positionPoint.getX() > map.getWidth() );

    }
     public void paint(Graphics g,int viewPortX, int viewPortY)
    {

    }

    public Sprite getObserveSprite() {
        return _pokemonOwner.getSprite();
    }
}
